<?php
include 'common.php';

$name = $_POST['name'];
$pwd = $_POST['pwd'];
$pwd1 = $_POST['pwd1'];
$email = $_POST['email'];
$yzm = strtoupper($_POST['yzm']);
$time = time();

$a = $_POST['a'];
$vcode = strtoupper($_SESSION['vcode']);

//条件判断
if($yzm != $vcode) exit(jump('验证码不正确',3,"register.php"));

if(strlen($name) <= 0) exit(jump('用户名不能为空',3,"register.php"));

if(strlen($pwd) <= 0) exit(jump('密码不能为空',3,"register.php?name={$name}&email={$email}"));

if($pwd != $pwd1) exit(jump('密码不一致',3,"register.php?name={$name}&email={$email}"));

$pattern = '/([\w\.\_]{2,10})@(\w{1,}).([a-z]{2,4})/';

if(!preg_match($pattern, $email))  exit(jump('邮箱格式不正确',3,"register.php?name={$name}"));

//验证完成，写入数据库
$pwd = md5($pwd);
$sql = "insert into ".PRE."user (name,password,email,reg_time,login_time)
							values('{$name}', '{$pwd}', '{$email}','{$time}', '{$time}' )";

$result = mysql_query($sql);
$id = mysql_insert_id($link);
if($result && mysql_insert_id() > 0){
	$userinfo = array('name'=>$name,'id'=>$id,'class'=>'2');
	$_SESSION['home'] = $userinfo;
	//注册成功，根据条件跳转页面
	if($a == 'cart') header('location:order_inf.php');
	//source 在head文件中设置的，用于跳转回来源页面
	echo jump('注册成功',3,$_SESSION['source']);
}else{
	//echo '注册失败，<a href="'.APP.'/register.php?name='. $name .'&email='. $email .'">请返回</a>';
	echo jump('注册失败',3,"register.php?name={$name}&email={$email}");
}



